package kr.haggenna.board.controller;

import kr.haggenna.board.dao.BoardDao;
import kr.haggenna.board.domain.BoardCommand;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class BoardDeleteController {
	@Autowired
	private BoardDao boardDao;
	private String formView = "boardDeleteForm";
	
	@RequestMapping("/boardDelete.do")
	public ModelAndView form(@RequestParam("board_num")int board_num){
		BoardCommand boardCommand = boardDao.selectBoard(board_num);
		return new ModelAndView(formView, "boardCommand", boardCommand);
	}
	
	@RequestMapping(value="/boardDelete.do",method=RequestMethod.POST)
	public String submit(@ModelAttribute BoardCommand boardCommand){
		boardDao.delete(boardCommand.getBoard_num());
		
		return "boardDeletePro";
	}
	
}
